import string
import string_operations as str_op
from document import *
from htmlParser import *

def parseHTML(input_string, new_doc):
    """
    Process the input_string, including links, title, 
    and body of the string. And put those in new_doc
    
    Return the updated new_doc, 
    and a list of processed words in the body of html
    """    
    html_parser = htmlParser()    
    html_parser.parse(input_string) 
    processLinks(new_doc, html_parser) 
    processTitle(new_doc, html_parser)   
    return processBody(html_parser)

def processLinks(new_doc, html_parser):  
    """
    Assign html's links to document's authors. 
    """  
    new_doc.authors = html_parser.links

def processTitle(new_doc, html_parser):
    """
    Assign html's title to document's title. 
    """
    new_doc.input_title = html_parser.title
    new_doc.title = str_op.parseString(html_parser.title)

def processBody(html_parser):
    """
    Process the html's body using string operations' parseString
    method. 
    """
    return str_op.parseString(html_parser.body)

if __name__=='__main__':
    input_string = "<html> <title> coolio </title> this is pretty spectacular. </html>"
    new_doc = document([], 'awesome', 'html')
    x = parseHTML(input_string, new_doc)
    self.output(new_doc.title)